package com.weimei.conversionTreasure.viewModel.myBinding;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.weimei.conversionTreasure.R;
import com.weimei.conversionTreasure.utils.GlideHandler;

public class WaneImageView {

    @BindingAdapter(value = {"intUrl", "placeholderRes"}, requireAll = false)
    public static void setImageUri(ImageView imageView, Integer url, int placeholderRes) {
        if (url != 0) {
            //使用Glide框架加载图片
            Glide.with(imageView.getContext())
                    .load(url)
                    .apply(new RequestOptions().placeholder(placeholderRes))
                    .into(imageView);
        }
    }

    @BindingAdapter(value = {"waneUrl"}, requireAll = false)
    public static void setWaneImageUri(ImageView imageView, String url) {
        if (!TextUtils.isEmpty(url)) {
            //使用Glide框架加载图片
            GlideHandler.loadUserHead(imageView.getContext(), url, 10, imageView);
        } else {
            Glide.with(imageView.getContext())
                    .load(R.mipmap.logo)
                    .into(imageView);
        }
    }


    @BindingAdapter(value = {"cirUrl", "radioSize"}, requireAll = false)
    public static void setCirImageUri(ImageView imageView, String url, int radioSize) {
        if (radioSize != 0) {
            if (!TextUtils.isEmpty(url)) {
                //使用Glide框架加载图片
                GlideHandler.loadLifeWm(imageView.getContext(), url, imageView, radioSize);
            } else {
                Glide.with(imageView.getContext())
                        .load(R.mipmap.logo)
                        .into(imageView);
            }
        } else {
            if (!TextUtils.isEmpty(url)) {
                //使用Glide框架加载图片
                GlideHandler.loadUserHead(imageView.getContext(), url, 10, imageView);
            } else {
                Glide.with(imageView.getContext())
                        .load(R.mipmap.logo)
                        .into(imageView);
            }
        }

    }

}
